<{include file="admin/public/header.html"}>
<div class="am-cf admin-main">
  <!-- sidebar start -->
  <{include file='admin/public/left.html'}>
  <!-- sidebar end -->

<!-- content start -->
<div class="admin-content">

  <div class="am-cf am-padding">
    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg"><{$nav[0]}></strong> / <small><{$nav[1]}></small></div>
    <div class="am-alert am-alert-success am-u-end success-msg" id="success-msg">添加成功！</div>
  </div>

  <form class="am-form" id="doc-vld-msg">
  <div class="am-tabs am-margin" data-am-tabs>
    <ul class="am-tabs-nav am-nav am-nav-tabs">
      <li class="am-active"><a href="#tab1">基本选项</a></li>
      <li><a href="#tab2">文章内容</a></li>
      <li><a href="#tab3">SEO 选项</a></li>
    </ul>
    <div class="am-tabs-bd">
      <div class="am-tab-panel am-fade am-in am-active" id="tab1">
        <div class="am-g am-margin-top">
          <div class="am-u-sm-4 am-u-md-2 am-text-right">分类</div>
          <div class="am-u-sm-8 am-u-md-10">
            <select data-am-selected="{btnSize: 'sm',maxHeight: 180}" name="cate_id" required>
              <option value="">请选择分类</option>
              <{foreach from=$list item="val"}>
              <{if $val.status==1}> 
              <option value="<{$val.id}>" <{if $article && $article.cate_id eq $val.id}> selected<{/if}>><{$val.cate}></option>
              <{else}>
              <{if $article && $article.cate_id eq $val.id}>
              <option value="<{$val.id}>" selected><{$val.cate}></option>
              <{/if}>
              <{/if}>
              	  <{foreach from=$val.child item="va"}>
                  <{if $va.status==1}> 
                  <option value="<{$va.id}>" <{if $article && $article.cate_id eq $va.id}> selected<{/if}>>&nbsp;&nbsp;└-<{$va.cate}></option>
                  <{else}>
                  <{if $article && $article.cate_id eq $va.id}>
                  <option value="<{$va.id}>" selected>&nbsp;&nbsp;└-<{$va.cate}></option>
                  <{/if}>
                  <{/if}>
                    <{foreach from=$va.child item="v"}>
                    <{if $v.status==1}> 
                    <option value="<{$v.id}>" <{if $article && $article.cate_id eq $v.id}> selected<{/if}>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└-<{$v.cate}></option>
                    <{else}>
                    <{if $article && $article.cate_id eq $v.id}>
                    <option value="<{$v.id}>" selected>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└-<{$v.cate}></option>
                    <{/if}>
                    <{/if}>
                    <{/foreach}>
	              <{/foreach}>
              <{/foreach}>
            </select>
          </div>
        </div>

        <div class="am-g am-margin-top">
          <div class="am-u-sm-4 am-u-md-2 am-text-right">审核状态</div>
          <div class="am-u-sm-8 am-u-md-10">
            <div class="am-btn-group" data-am-button>
              <label class="am-btn am-btn-default am-btn-xs <{if !$article}> am-active<{elseif $article && $article.audit==1}> am-active<{/if}>">
                <input type="radio" name="audit" id="option1" value="1"> 通过
              </label>
              <label class="am-btn am-btn-default am-btn-xs <{if $article && $article.audit==2}> am-active<{/if}>">
                <input type="radio" name="audit" id="option3" value="2"> 不通过
              </label>
              <label class="am-btn am-btn-default am-btn-xs <{if $article && $article.audit==0}> am-active<{/if}>">
                <input type="radio" name="audit" id="option3" value="0"> 待审核
              </label>
            </div>
          </div>
        </div>
        
        <div class="am-g am-margin-top">
          <div class="am-u-sm-4 am-u-md-2 am-text-right">推荐类型</div>
          <div class="am-u-sm-8 am-u-md-10">
            <div class="am-btn-group" data-am-button>
              <label class="am-btn am-btn-default am-btn-xs am-active<{if $article && $article.comment==1}> am-active<{/if}>">
                <input type="checkbox" name="comment" value="1"> 允许评论
              </label>
              <label class="am-btn am-btn-default am-btn-xs<{if $article && $article.top==1}> am-active<{/if}>">
                <input type="checkbox" name="top" value="1"> 置顶
              </label>
              <label class="am-btn am-btn-default am-btn-xs<{if $article && $article.recommend==1}> am-active<{/if}>">
                <input type="checkbox" name="recommend" value="1"> 推荐
              </label>
              <label class="am-btn am-btn-default am-btn-xs<{if $article && $article.hot==1}> am-active<{/if}>">
                <input type="checkbox" name="hot" value="1"> 热门
              </label>
            </div>
          </div>
        </div>

        
        <div class="am-g am-margin-top">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              排序
            </div>
            <div class="am-u-sm-8 am-u-md-2 am-u-end">
              <input name="sort" type="text" class="am-input-sm" value="<{if $article}><{$article.sort}><{/if}>"  placeholder="默认50">
            </div>
        </div>

        <div class="am-g am-margin-top">
          <div class="am-u-sm-4 am-u-md-2 am-text-right">
            发布时间
          </div>
          <div class="am-u-sm-8 am-u-md-3 am-u-end">
              <div class="am-form-group am-form-icon">
                <i class="am-icon-calendar"></i>
                <input name="publish_time" type="text" value="<{if $article}><{$article.publish_time|date_format:'%Y-%m-%d %H:%M:%S'}><{/if}>" id="datetimepicker" class="am-form-field am-input-sm form-datetime" placeholder="时间">
              </div>
          </div>
        </div>

      </div>
		
      <div class="am-tab-panel am-fade" id="tab2">
        <form class="am-form">
          <div class="am-g am-margin-top am-form-group">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              文章标题
            </div>
            <div class="am-u-sm-8 am-u-md-4 am-u-end">
              <input type="text" class="am-input-sm"  name="title" data-validation-message="文章标题必填" placeholder="输入文章标题" value="<{if $article}><{$article.title}><{/if}>" required>
            </div>
          </div>

          <div class="am-g am-margin-top">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              文章作者
            </div>
            <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
              <input type="text" class="am-input-sm" value="<{if $article}><{$article.username}><{else}><{$smarty.session.user.info.username}><{/if}>" readonly>
            </div>
          </div>

          <div class="am-g am-margin-top">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              内容摘要
            </div>
            <div class="am-u-sm-8 am-u-md-4">
              <input type="text" class="am-input-sm" name="desc" value="<{if $article}><{$article.desc}><{/if}>">
            </div>
            <div class="am-u-sm-12 am-u-md-6">不填写则自动截取内容前255字符</div>
          </div>

          <div class="am-g am-margin-top-sm">
            <div class="am-u-sm-12 am-u-md-2 am-text-right admin-form-text">
              正文内容
            </div>
            <div class="am-u-sm-16 am-u-md-6 am-u-end">
              <textarea rows="16" name="content"><{if $article}><{$article.content}><{/if}></textarea>
            </div>
          </div>

        </form>
      </div>
      <div class="am-tab-panel am-fade" id="tab3">
          <div class="am-g am-margin-top-sm">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              SEO 标题
            </div>
            <div class="am-u-sm-8 am-u-md-4 am-u-end">
              <input name="seo_title" type="text" class="am-input-sm" value="<{if $article}><{$article.seo_title}><{/if}>">
            </div>
          </div>

          <div class="am-g am-margin-top-sm">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              SEO 关键字
            </div>
            <div class="am-u-sm-8 am-u-md-4 am-u-end">
              <input name="seo_keyword" type="text" class="am-input-sm" value="<{if $article}><{$article.seo_keyword}><{/if}>">
            </div>
          </div>

          <div class="am-g am-margin-top-sm">
            <div class="am-u-sm-4 am-u-md-2 am-text-right">
              SEO 描述
            </div>
            <div class="am-u-sm-8 am-u-md-4 am-u-end">
              <textarea name="seo_desc" rows="4"><{if $article}><{$article.seo_desc}><{/if}></textarea>
            </div>
          </div>
      </div>

      <{if $article}>
      <input name="id" type="hidden" class="am-input-sm" value="<{$article.id}>">
      <{/if}>
    </div>
  </div>
  </form>
  <div class="am-margin">
    <button id="save-sure" type="submit" class="am-btn am-btn-primary am-btn-xs">提交保存</button>
    <button id="save-forgive" type="button" class="am-btn am-btn-primary am-btn-xs" onclick="jumpUrl('/admin/article/index')">放弃保存</button>
  </div>
</div>
<!-- content end -->

</div>
<{include file='admin/public/footer.html'}>

<script src="<{$picker_style_url}>kindeditor/kindeditor-min.js"></script>
<script src="<{$picker_style_url}>kindeditor/lang/zh_CN.js"></script>
<script>
  var editor;
  KindEditor.ready(function(K) {
    editor = K.create('textarea[name="content"]', {
      allowFileManager : true
    });
  });
  $(function() {
    $.fn.datetimepicker.dates['zh-CN'] = {
      days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
      daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
      daysMin:  ["日", "一", "二", "三", "四", "五", "六", "日"],
      months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
      monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
      today: "今日",
      suffix: [],
      meridiem: ["上午", "下午"]
    };
    $('.form-datetime').datetimepicker({
      language:  'zh-CN', 
      format: 'yyyy-mm-dd hh:ii:ss',
      autoclose: true,
      todayBtn: true,
      pickerPosition: 'bottom-left'
    });
  });
	$('#save-sure').on('click', function() {
    var postData = $('#doc-vld-msg').serializeArray();
    postData.push({
      "name": "content",
      "value": editor.html()
    });
    var jumpUrl = '/admin/article/index';
    var url = "/admin/article/add";
    post(url, postData, jumpUrl);
	});

	$(function() {
		  $('#doc-vld-msg').validator({
		    onValid: function(validity) {
		      $(validity.field).closest('.am-form-group').find('.am-alert').hide();
		    },

		    onInValid: function(validity) {
		      var $field = $(validity.field);
		      var $group = $field.closest('.am-form-group');
		      var $alert = $group.find('.am-alert');
		      // 使用自定义的提示信息 或 插件内置的提示信息
		      var msg = $field.data('validationMessage') || this.getValidationMessage(validity);

		      if (!$alert.length) {
		        $alert = $('<div class="am-alert am-alert-danger am-u-md-2 am-u-end" id="danger-msg"></div>').hide().
		          appendTo($group);
		      }

		      $alert.html(msg).show();
		    }
		  });
			  
		});
</script>
</body>
</html>
